package com.example.demo01.controller;

import cn.hutool.core.bean.BeanUtil;
import com.example.demo01.po.Past;
import com.example.demo01.po.Result;
import com.example.demo01.po.Yiyun;
import com.example.demo01.service.YiyunService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/content")
public class YiyunController {

    @Autowired
    YiyunService yiyunService;

    @GetMapping("/daily/{id}")
    public Result<Yiyun> daily(@PathVariable("id") Integer id) {
        Yiyun yiyun = yiyunService.getById(id);
        return Result.success(yiyun);
    }

    @GetMapping("/past-dailies")
    public Result<List<Past>> pastDailies() {
        List<Yiyun> list = yiyunService.list();

        List<Past> pastList = new ArrayList<>();

        for (Yiyun yiyun : list) {

            Past past = new Past();

            BeanUtil.copyProperties(yiyun, past);

            pastList.add(past);

        }

        return Result.success(pastList);
    }

}
